//
// Copyright 2010 Marcel Urbanek
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//      http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package de.urbiworx.typewriter;

import java.util.LinkedList;
import java.util.List;

import org.apache.batik.css.engine.sac.ExtendedSelector;
import org.w3c.css.sac.CSSException;
import org.w3c.css.sac.DocumentHandler;
import org.w3c.css.sac.InputSource;
import org.w3c.css.sac.LexicalUnit;
import org.w3c.css.sac.SACMediaList;
import org.w3c.css.sac.SelectorList;

public class ExtractDocumentHandler implements DocumentHandler {

	private List<ComplexSelector>allSelectors=new LinkedList<ComplexSelector>();
	private ComplexSelector selector;
	
	public List<ComplexSelector> getAllSelectors() {
		return allSelectors;
	}

	public void comment(String arg0) throws CSSException {
		// TODO Auto-generated method stub

	}

	public void endDocument(InputSource arg0) throws CSSException {
		// TODO Auto-generated method stub

	}

	public void endFontFace() throws CSSException {
		// TODO Auto-generated method stub

	}

	public void endMedia(SACMediaList arg0) throws CSSException {
		// TODO Auto-generated method stub

	}

	public void endPage(String arg0, String arg1) throws CSSException {
		// TODO Auto-generated method stub

	}

	public void endSelector(SelectorList arg0) throws CSSException {
		// TODO Auto-generated method stub

	}

	public void ignorableAtRule(String arg0) throws CSSException {
		// TODO Auto-generated method stub

	}

	public void importStyle(String arg0, SACMediaList arg1, String arg2)
			throws CSSException {
		// TODO Auto-generated method stub

	}

	public void namespaceDeclaration(String arg0, String arg1)
			throws CSSException {
		// TODO Auto-generated method stub

	}

	public void property(String property, LexicalUnit unit, boolean flag)
			throws CSSException {
		selector.getProperties().put(property, unit);

	}

	public void startDocument(InputSource arg0) throws CSSException {
		// TODO Auto-generated method stub

	}

	public void startFontFace() throws CSSException {
		// TODO Auto-generated method stub

	}

	public void startMedia(SACMediaList arg0) throws CSSException {
		// TODO Auto-generated method stub

	}

	public void startPage(String arg0, String arg1) throws CSSException {
		// TODO Auto-generated method stub

	}

	public void startSelector(SelectorList arg0) throws CSSException {
		selector=new ComplexSelector();
		ExtendedSelector currentSelector=(ExtendedSelector)arg0.item(0);
		selector.setSelector(currentSelector);
		allSelectors.add(selector);

	}

}
